
cd "/Users/cason/Dropbox/Research/Emiss_Trade_price_controls/data/"

use Contracts_11sessions.dta

** Drop practice period **
drop if Period<1

** Keep only the transaction prices **
drop if Traded<1

sort sess_num Period
** Merge in the emission shocks and investment totals from the Subjects table **
merge m:1 sess_num Period using invest_shocks.dta

** Create an index revTradeOrder that numbers the transactions in reverse order within period **
gsort sess_num -MktTime
gen revTradeOrder=0

replace revTradeOrder=1 if Period != Period[_n-1]
replace revTradeOrder = revTradeOrder[_n-1]+1 if revTradeOrder==0

** Figures 5 and 6 of the paper **
by pri_control totalInvest, sort : tabstat p if revTradeOrder<6, statistics( mean semean count ) by(emissShock)

** Overall summary for reporting at start of subsection 4.2 in paper **
tabstat p, statistics( mean semean count ) by(pri_control)
tabstat p if revTradeOrder<6, statistics( mean semean count ) by(pri_control)
tabstat p if revTradeOrder<4, statistics( mean semean count ) by(pri_control)

** Summarize each period mean price over the final 5 prices each period *
drop if revTradeOrder>5
collapse (mean) meanPrice=p (mean) emissShock totalInvest, by(pri_control sess_num Period)

** Transform the cost shock so that the equilibrium price gap is 15/20 for each unit **
gen transhock = .
replace transhock = 40 if emissShock == 0
replace transhock = 20 if emissShock == 1
replace transhock = 0 if emissShock == 3
replace transhock = -20 if emissShock == 4
replace transhock = -40 if emissShock == 5

** Regressions reported in Table 3 **
iis sess_num
by pri_control, sort : xtreg meanPrice transhock totalInvest Period, re
** Drop the first 5 periods, Panel B of Table 3 **
by pri_control, sort : xtreg meanPrice transhock totalInvest Period if Period>5, re

** Go back to select only the final 3 trades each period for regressions **
clear

use Contracts_11sessions.dta

** Drop practice period **
drop if Period<1

** Keep only the transaction prices **
drop if Traded<1

sort sess_num Period
** Merge in the emission shocks and investment totals from the Subjects table **
merge m:1 sess_num Period using invest_shocks.dta

** Create an index revTradeOrder that numbers the transactions in reverse order within period **
gsort sess_num -MktTime
gen revTradeOrder=0

replace revTradeOrder=1 if Period != Period[_n-1]
replace revTradeOrder = revTradeOrder[_n-1]+1 if revTradeOrder==0

** Summarize each period mean price, now using final 3 prices each period *
drop if revTradeOrder>3
collapse (mean) meanPrice=p (mean) emissShock totalInvest, by(pri_control sess_num Period)

** Transform the cost shock so that the equilibrium price gap is 15/20 for each unit **
gen transhock = .
replace transhock = 40 if emissShock == 0
replace transhock = 20 if emissShock == 1
replace transhock = 0 if emissShock == 3
replace transhock = -20 if emissShock == 4
replace transhock = -40 if emissShock == 5

** Regressions reported in Table 3 **
iis sess_num
by pri_control, sort : xtreg meanPrice transhock totalInvest Period, re
** Drop the first 5 periods, Panel B of Table 3 **
by pri_control, sort : xtreg meanPrice transhock totalInvest Period if Period>5, re

** Go back to consider all trades for nonparametric tests reported in opening of Subsection 4.2 **
clear

use Contracts_11sessions.dta

** Drop practice period **
drop if Period<1

** Keep only the transaction prices **
drop if Traded<1

sort sess_num Period
** Merge in the emission shocks and investment totals from the Subjects table **
merge m:1 sess_num Period using invest_shocks.dta

** Create an index revTradeOrder that numbers the transactions in reverse order within period **
gsort sess_num -MktTime
gen revTradeOrder=0

replace revTradeOrder=1 if Period != Period[_n-1]
replace revTradeOrder = revTradeOrder[_n-1]+1 if revTradeOrder==0

** Summarize each sessions mean price *
collapse (mean) meanPrice=p (mean) emissShock totalInvest, by(pri_control sess_num)

ranksum meanPrice, by(pri_control)

** Comkpare within-period price dispersion (footnote 23) **
clear

use Contracts_11sessions.dta

** Drop practice period **
drop if Period<1

** Keep only the transaction prices **
drop if Traded<1

sort sess_num Period
** Merge in the emission shocks and investment totals from the Subjects table **
merge m:1 sess_num Period using invest_shocks.dta

** Create an index revTradeOrder that numbers the transactions in reverse order within period **
gsort sess_num -MktTime
gen revTradeOrder=0

replace revTradeOrder=1 if Period != Period[_n-1]
replace revTradeOrder = revTradeOrder[_n-1]+1 if revTradeOrder==0

** Summarize each periods mean price and standard deviation *
collapse (mean) meanPrice=p (sd) sdPrice=p, by(pri_control sess_num Period)

tabstat sdPrice, statistics( mean semean count ) by(pri_control)
tabstat sdPrice if Period>5, statistics( mean semean count ) by(pri_control)

** Do statistical comparison for Periods 6-16 **
drop if Period<6
collapse (mean) sdPrice, by(pri_control sess_num)

ranksum sdPrice, by(pri_control)

